﻿namespace ExamV5.WorkExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmEditRubricInfo : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected DropDownList DDLSubject;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected TextBox txtOKAnswerAFen;
        protected TextBox txtOKAnswerBFen;
        protected TextBox txtOKAnswerCFen;
        protected TextBox txtOKAnswerDFen;
        protected TextBox txtOKAnswerEFen;
        protected TextBox txtOKAnswerFFen;
        protected TextBox txtRubricAA;
        protected TextBox txtRubricAB;
        protected TextBox txtRubricAC;
        protected TextBox txtRubricAD;
        protected TextBox txtRubricAE;
        protected TextBox txtRubricAF;
        //protected HtmlInputHidden txtRubricDocA;
        protected string editorContent;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string cmdText = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            string str5 = "";
            string str6 = "";
            DateTime.Now.ToString();
            string text1 = this.httpCookie_0.Value;
            string str7 = "";
            string str8 = "";
            string str9 = "";
            string str10 = "";
            string str11 = "";
            string str12 = "";
            str7 = this.txtRubricAA.Text.Replace("'", "＇").Replace("#", "＃");
            str8 = this.txtRubricAB.Text.Replace("'", "＇").Replace("#", "＃");
            str9 = this.txtRubricAC.Text.Replace("'", "＇").Replace("#", "＃");
            str10 = this.txtRubricAD.Text.Replace("'", "＇").Replace("#", "＃");
            str11 = this.txtRubricAE.Text.Replace("'", "＇").Replace("#", "＃");
            str12 = this.txtRubricAF.Text.Replace("'", "＇").Replace("#", "＃");
            if ((this.DDLSubject.SelectedItem.Value != "0") && (this.DDLSubject.SelectedIndex != -1))
            {
                str2 = this.DDLSubject.SelectedItem.Value;
                str3 = "A";
                var editorValue = this.Request.Form["editorContent"].ToString();
                //if (this.txtRubricDocA.Value.Trim() == "")
                //{
                //    base.Response.Write("<script>alert('请输入题目内容！')</script>");
                //}
                if (editorValue.Trim() == "")
                {
                    base.Response.Write("<script>alert('请输入题目内容！')</script>");
                }
                else
                {
                    str4 = editorValue.Trim();
                    if ((str7.Trim() != "") ? !(this.txtOKAnswerAFen.Text.Trim() == "") : true)
                    {
                        if ((str8.Trim() != "") ? !(this.txtOKAnswerBFen.Text.Trim() == "") : true)
                        {
                            if ((str9.Trim() != "") ? !(this.txtOKAnswerCFen.Text.Trim() == "") : true)
                            {
                                if ((str10.Trim() == "") || (this.txtOKAnswerDFen.Text.Trim() != ""))
                                {
                                    if ((str11.Trim() != "") ? !(this.txtOKAnswerEFen.Text.Trim() == "") : true)
                                    {
                                        if ((str12.Trim() != "") ? !(this.txtOKAnswerFFen.Text.Trim() == "") : true)
                                        {
                                            if ((((str7.Trim() == "") || (str8.Trim() == "")) || (this.txtOKAnswerAFen.Text.Trim() == "")) || (this.txtOKAnswerBFen.Text.Trim() == ""))
                                            {
                                                base.Response.Write("<script>alert('请选择输入答案选项或选项得分！')</script>");
                                            }
                                            else
                                            {
                                                str5 = str7 + "#" + str8 + "#" + str9 + "#" + str10 + "#" + str11 + "#" + str12;
                                                str6 = (this.txtOKAnswerAFen.Text.Trim() + "#" + this.txtOKAnswerBFen.Text.Trim() + "#" + this.txtOKAnswerCFen.Text.Trim() + "#" + this.txtOKAnswerDFen.Text.Trim() + "#" + this.txtOKAnswerEFen.Text.Trim() + "#" + this.txtOKAnswerFFen.Text.Trim()).Replace("#####", "").Replace("####", "").Replace("###", "").Replace("##", "");
                                                str5 = str5.Replace("<P>", "").Replace("<P align=right>", "").Replace("<P align=center>", "").Replace("<P align=left>", "").Replace("</P>", "");
                                                str4 = str4.Replace("<P>", "").Replace("<P align=right>", "").Replace("<P align=center>", "").Replace("<P align=left>", "").Replace("</P>", "");
                                                if (this.int_0 != 0)
                                                {
                                                    cmdText = "update WorkRubric set OptionAnswer=@OptionAnswer,OKAnswer=@OKAnswer,RubricType=@RubricType,SubjectID=@SubjectID,RubricTitle=@RubricTitle,CreatNumberNO=@CreatNumberNO where ID=" + this.int_0;
                                                }
                                                else
                                                {
                                                    cmdText = "Insert into WorkRubric(RubricType,SubjectID,RubricTitle,OptionAnswer,OKAnswer,CreatTime,CreatNumberNO) Values(";
                                                    cmdText = cmdText + "@RubricType,@SubjectID,@RubricTitle,@OptionAnswer,@OKAnswer,@CreatTime,@CreatNumberNO)";
                                                }
                                                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                                                connection.Open();
                                                SqlCommand command = new SqlCommand(cmdText, connection);
                                                command.Parameters.Add("@RubricType", SqlDbType.Char, 1).Value = str3;
                                                command.Parameters.Add("@SubjectID", SqlDbType.Int).Value = str2;
                                                command.Parameters.Add("@RubricTitle", SqlDbType.Text).Value = str4;
                                                command.Parameters.Add("@OptionAnswer", SqlDbType.Text).Value = str5;
                                                command.Parameters.Add("@OKAnswer", SqlDbType.VarChar, 0x3e8).Value = str6;
                                                command.Parameters.Add("@CreatTime", SqlDbType.VarChar, 20).Value = DateTime.Now.ToString();
                                                command.Parameters.Add("@CreatNumberNO", SqlDbType.VarChar, 20).Value = this.httpCookie_0.Value;
                                                command.ExecuteNonQuery();
                                                command.Dispose();
                                                connection.Close();
                                                connection.Dispose();
                                                //this.txtRubricDocA.Value = "";
                                                this.editorContent = "";
                                                this.txtRubricAA.Text = "";
                                                this.txtRubricAB.Text = "";
                                                this.txtRubricAC.Text = "";
                                                this.txtRubricAD.Text = "";
                                                this.txtRubricAE.Text = "";
                                                this.txtRubricAF.Text = "";
                                                this.txtOKAnswerAFen.Text = "";
                                                this.txtOKAnswerBFen.Text = "";
                                                this.txtOKAnswerCFen.Text = "";
                                                this.txtOKAnswerDFen.Text = "";
                                                this.txtOKAnswerEFen.Text = "";
                                                this.txtOKAnswerFFen.Text = "";
                                                if (this.int_0 != 0)
                                                {
                                                    this.publicFun_0.ExecuteSql("insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('修改职业测评[" + str4 + "]题目信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                                                    base.Response.Write("<script>alert('修改试题操作成功！');parent.location.reload();</script>");
                                                }
                                                else
                                                {
                                                    this.publicFun_0.ExecuteSql("insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('添加职业测评[" + str4 + "]题目信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')");
                                                    base.Response.Write("<script>alert('添加试题操作成功！')</script>");
                                                    base.Response.Write("<script>parent.location.reload();</script>");
                                                }
                                            }
                                        }
                                        else
                                        {
                                            base.Response.Write("<script>alert('请输入答案F选项的得分分值！')</script>");
                                        }
                                    }
                                    else
                                    {
                                        base.Response.Write("<script>alert('请输入答案E选项的得分分值！')</script>");
                                    }
                                }
                                else
                                {
                                    base.Response.Write("<script>alert('请输入答案D选项的得分分值！')</script>");
                                }
                            }
                            else
                            {
                                base.Response.Write("<script>alert('请输入答案C选项的得分分值！')</script>");
                            }
                        }
                        else
                        {
                            base.Response.Write("<script>alert('请输入答案B选项的得分分值！')</script>");
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('请输入答案A选项的得分分值！')</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script>alert('请选择所属科目！')</script>");
            }
        }

        private void method_0()
        {
            try
            {
                string str2 = "";
                string str3 = "";
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                SqlCommand command = new SqlCommand("select ID,SubjectID,RubricType,RubricTitle,OptionAnswer,OKAnswer from WorkRubric where ID=" + this.int_0, connection);
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    str2 = reader["OptionAnswer"].ToString().Trim();
                    str3 = reader["OKAnswer"].ToString().Trim();
                    this.DDLSubject.SelectedIndex = -1;
                    string str5 = reader["RubricType"].ToString();
                    if ((str5 != null) && (str5 == "A"))
                    {
                        //this.txtRubricDocA.Value = reader["RubricTitle"].ToString();
                        this.editorContent = reader["RubricTitle"].ToString();
                        string[] strArray = str2.Split(new char[] { '#' });
                        string[] strArray2 = str3.Split(new char[] { '#' });
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            if (strArray[i].ToString() != "")
                            {
                                switch (i)
                                {
                                    case 0:
                                        this.txtRubricAA.Text = strArray[i].ToString();
                                        this.txtOKAnswerAFen.Text = strArray2[i].ToString();
                                        break;

                                    case 1:
                                        this.txtRubricAB.Text = strArray[i].ToString();
                                        this.txtOKAnswerBFen.Text = strArray2[i].ToString();
                                        break;

                                    case 2:
                                        this.txtRubricAC.Text = strArray[i].ToString();
                                        this.txtOKAnswerCFen.Text = strArray2[i].ToString();
                                        break;

                                    case 3:
                                        this.txtRubricAD.Text = strArray[i].ToString();
                                        this.txtOKAnswerDFen.Text = strArray2[i].ToString();
                                        break;

                                    case 4:
                                        this.txtRubricAE.Text = strArray[i].ToString();
                                        this.txtOKAnswerEFen.Text = strArray2[i].ToString();
                                        break;

                                    case 5:
                                        this.txtRubricAF.Text = strArray[i].ToString();
                                        this.txtOKAnswerFFen.Text = strArray2[i].ToString();
                                        break;
                                }
                            }
                        }
                    }
                    this.DDLSubject.Items.FindByValue(reader["SubjectID"].ToString()).Selected = true;
                }
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch
            {
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                    else
                    {
                        SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                        connection.Open();
                        SqlCommand command = new SqlCommand("select AddRubric,ManagRubric from UserPower where UserCode='" + this.httpCookie_0.Value + "'", connection);
                        SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                        if (reader.Read())
                        {
                            this.ViewState["AddPower"] = reader["AddRubric"].ToString();
                            this.ViewState["ManagPower"] = reader["ManagRubric"].ToString();
                        }
                        reader.Close();
                        command.Dispose();
                        connection.Close();
                        connection.Dispose();
                        this.publicFun_0.LoadSubjectInfo(this.DDLSubject, this.httpCookie_0.Value, this.ViewState["ManagPower"].ToString(), "E", this.httpCookie_3.Value);
                        this.DDLSubject.Items.Insert(0, new ListItem("--请选择科目信息--", "0"));
                        if (this.int_0 != 0)
                        {
                            this.method_0();
                            bool flag = false;
                            if (!(this.publicFun_0.GetValues("select PaperID from WorkPaperData where '#'+RubricS+RubricD like '%#" + this.int_0 + "#%' and  PaperID in(select PaperID from WorkExamUser where Flag<>'A')", "PaperID") == ""))
                            {
                                flag = true;
                                this.butDefault.Visible = false;
                            }
                            else
                            {
                                this.butDefault.Visible = true;
                            }
                            if (flag)
                            {
                                base.Response.Write("<script>alert('因此道试题已被试卷使用并有考生作答记录所以此道试题无法修改！')</script>");
                            }
                        }
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

